package com.aven.blog.action;


import com.aven.blog.bean.User;
import com.aven.blog.dao.IUserDao;
import com.aven.blog.dao.impl.IUserDaoImpl;
import com.aven.blog.service.IUserService;
import com.aven.blog.service.Impl.UserServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class UserAction extends ActionSupport implements ModelDriven<User> {
    private User user = new User();  //页面获取的用户信息

    public String Register() {
        System.out.println("注册"+user);
        IUserService userService = new UserServiceImpl();
        if (userService.addUser(user)==1){
            return SUCCESS;
        }
        return ERROR;
    }
    public String Login() {
        System.out.println("登陆user"+user);

        IUserService userService = new UserServiceImpl();
        User t_user = userService.findByUsername(user.getUsername());

        System.out.println("t_user"+t_user);
        if (t_user != null) {//找到用户
            if (user.getPassword().equals(t_user.getPassword())) {
                return SUCCESS;
            } else {
                System.out.println("密码错误");
            }
        }
        System.out.println(t_user+"用户不存在");
        return ERROR;
    }
    //模型驱动接收参数，表单字段写username即可
    @Override
    public User getModel() {
        return user;
    }
}
